Test Series - Data Structure

Test Number 28/115

Q: What would be the solution to the given prefix notation?

- + 5 / 10 5 5
A. 2
B. 5
C. 10
D. 7
Solution: The infix notation of the given prefix notation is 5+10/5-5 which gives us 2 as our answer.
Q: What would be the solution to the given prefix notation?

/ / / / 16 4 2 1
A. 1
B. 4
C. 2
D. 8
Solution: The infix notation to the given prefix notation is 16/4/2/1 which gives us 1 as our answer. The infix notation is got from the prefix notation by traversing the equation from the right.
Q: What would be the solution to the given prefix notation?

+ 9 * 3 / 8 4
A. 14
B. 15
C. 18
D. 12
Solution: The infix notation for the given prefix notation is (9+(3*(8/4))) which solves to 15. So 15 is correct answer.
Q: What would be the solution to the given prefix notation?

- + 1 2 * 3 / 6 2
A. 6
B. -6
C. 3
D.  -3
Solution: The infix notation for the given prefix notation is (1+2)-3*(6/2). The result of the given equation is -6.
Q: What would be the solution to the given prefix notation?

- * 1 5 / * / 6 3 6 2
A. 1
B. 0
C.  -1
D. -2
Solution: The infix notation for the given prefix notation is (1*5)-(6/3)*6/2. The result of the equation is -1.
Q: What would be the solution to the given prefix notation?

* / + 1 2 / 4 2 + 3 5
A. 12
B. 7.5
C. 9
D. 13.5
Solution: The infix notation of the given prefix notation is ((1+2)/(4/2))*(3+5) which solves to (3/2)*8 which by solving gives us 12.
Q: Given a prefix and a postfix notation what are the difference between them?
A. The postfix equation is solved starting from the left whereas the prefix notation is solved from the right
B. The postfix equation is solved starting from the right whereas the prefix notation is solved from the left
C. Both equations are solved starting from the same side(right)
D. Both equations are solved starting from the same side(left)
Solution: The postfix notation is solved starting from left but whereas the prefix notation is reversed after creating them, therefore it’s solved starting from right.
Q: When converting the prefix notation into an infix notation, the first step to be followed is ________
A. Reverse the equation
B. Push the equation to the stack
C. Push the equation onto the queue
D. Push the equation to the stack or queue
Solution: The steps that are followed are: the equation is reversed, pushed onto a stack, popped one by one and solved. Therefore the first step is reversing the equation.
Q: The time complexity of converting a prefix notation to infix notation is _________
A. O(n) where n is the length of the equation
B. O(n) where n is number of operands
C. O(1)
D. O(logn) where n is length of the equation
Solution: The processes that are involved are reversing the equation (O(n)), pushing them all onto the stack(O(n)), and popping them one by one and solving them (O(n)). Hence the answer is O(n) where n is the length of the equation.
Q: Given two processes (conversion of postfix equation to infix notation and conversion of prefix notation to infix notation), which of the following is easier to implement?
A. Both are easy to implement
B. Conversion of postfix equation to infix equation is harder than converting a prefix notation to infix notation
C. Conversion of postfix equation to infix equation is easier than converting a prefix notation to infix notation
D. Insufficient data
Solution: As the conversion of prefix notation to infix notation involves reversing the equation, the latter is harder to implement than postfix to infix process.

You Have Score    /10